package com.silence.ByteDance;

import java.util.*;

// 数字字母问号排序
public class easy_85 {
    public static String solution(String inp) {
        List<Character> letters = new ArrayList<>();
        List<Character> digits = new ArrayList<>();

        for (char c : inp.toCharArray()) {
            if (Character.isLetter(c)) {
                letters.add(c);
            } else if (Character.isDigit(c)) {
                digits.add(c);
            }
        }
        // 字母升序
        Collections.sort(letters);
        // 数字降序
        digits.sort(Collections.reverseOrder());


        String res = new String();
        int letterIndex = 0;
        int digitIndex = 0;
        for (char c : inp.toCharArray()) {
            if (Character.isLetter(c)) {
                res += letters.get(letterIndex++);
            } else if (Character.isDigit(c)) {
                res += digits.get(digitIndex++);
            } else {
                res += c;
            }
        }

        return res;
    }

    public static void main(String[] args) {
        // 添加测试用例
        System.out.println(solution("12A?zc").equals("21A?cz"));  // true
        System.out.println(solution("1Ad?z?t24").equals("4Ad?t?z21"));  // true
        System.out.println(solution("???123??zxy?").equals("???321??xyz?"));  // true
    }
}
